package com.kk.provider.service.impl;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.lang.generator.UUIDGenerator;
import com.kk.provider.service.IMessageProvider;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * the class of springcloud-alibaba
 *
 * <p>
 * .
 *
 * @author little_lunatic
 * @date 2022-12-01
 */
@EnableBinding(Source.class) //定义消息的推送管道
public class MessageProviderImpl implements IMessageProvider {

    @Autowired
    private MessageChannel output;

    @Override
    public String sendMessage() {
        UUID uuid = UUID.fastUUID();
        boolean send = output.send(MessageBuilder.withPayload(uuid).build());
        System.out.println("*****serial: "+uuid);
        if (send){
            System.out.println("发送成功");
        }
        return uuid.toString();
    }
}
